from web_server_function.CourseServer import course_server
from web_server_function.ServerUtils import server_utils
from utils.ReadUtil import read_util
import argparse


# if __name__ == '__main__':
#     # 使用测试教研主管登录之后获取cookie中的jession字段
#     jsessionid_value = server_utils.extract_cookies_from_request('https://testadmin.xkb365.com/main.html',
#                                                                  phone='15055555553', password='123456')
#     # 根据课程标题查询课程rsNo
#     resp = course_server.find_course_by_title(jsessionid_value, '测试课程习题排序问题啊哈哈')
#     # print(resp)
#     rsNo = course_server.query_course_rsNo(resp)
#
#     res = course_server.audit_course(jsessionid_value, rsNo, '2', '客官都可以哦')
#     print(res)


def audit_main(course_title, approval_status, remark):
    # 测试教研主管登录
    server_utils.login_background(read_util.read_data()['后台账号密码']['测试教研主管账号'],
                                  read_util.read_data()['后台账号密码']['测试教研主管密码'])
    # 根据课程标题查询课程rsNo
    resp = course_server.find_course_by_title(course_title)
    print(resp)
    rs_no = course_server.query_course_rsNo(resp)
    print(rs_no)
    # 审核课程
    res = course_server.audit_course(rs_no, approval_status, remark)
    print(res)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='执行审核课程模块操作')
    parser.add_argument('course_title', type=str, help='课程标题')
    parser.add_argument('approval_status', type=str, help='审核状态')
    parser.add_argument('remark', type=str, help='审核原因')
    args = parser.parse_args()

    audit_main(args.course_title, args.approval_status, args.remark)
